package com.person.commons.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * A class that encapsulate and provide pagination information. Such as page
 * number, size, count, total pages and data etc
 * 
 * @author Andy (latest modification by $Author: andy $)
 * @version $Revision: 1.2 $ $Date: 2006/08/28 08:53:23 $
 */
public class FlipPageInfo {

	private Integer page=new Integer(0);   // 当前页数 从1开始
	
	private long totalPageCount =0;  // 总页数

	private Integer size = 50;// 每页的显示记录数

	private Long total =new Long(0); // 总记录数

	private List data; // 当前页中存放的记

	/** sort field */
	private String sortField;

	/** sort order */
	private String sortOrder;

	
	
	public FlipPageInfo() {
		data = new ArrayList();
	}

	/**
	 * 构造函数
	 * @param page	 当前页号
	 * @param total      数据库中总记录条
	 * @param size       本页容量
	 * @param data	         本页包含的数据
	 */
	public FlipPageInfo(int page, long total, int size, List data) {
		this.page = page;
		this.total = total;
		this.size = size;
		this.data = data;
	}
	
	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

	public List getData() {
		return data;
	}

	public void setData(List data) {
		this.data.clear();
		this.data.addAll(data);
	}

	public Long getTotal() {
		return total;
	}

	protected void setTotal(Long total) {
		this.total = total;
	}

	public Integer getDataCount() {
		if (data != null) {
			return new Integer(data.size());
		} else {
			return new Integer(0);
		}
	}

	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public String getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(String sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Integer getPages() {
		if (size != null && total != null) {
			BigDecimal sizeBD = new BigDecimal(size.intValue());
			BigDecimal totalBD = new BigDecimal(total.intValue());

			return new Integer(totalBD.divide(sizeBD, 0,
					BigDecimal.ROUND_CEILING).intValue());
		} else {
			return new Integer(0);
		}
	}

	public long getTotalPageCount() {
		if (total % size == 0)
			totalPageCount =total/ size;
		else
			totalPageCount= total/ size + 1;
		return totalPageCount;
	}

	public void setTotalPageCount(long totalPageCount) {
		
		this.totalPageCount = totalPageCount;
	}

}
